import type { ReactNode } from "react";
import type { TreeNodeType, TreeDataType, TreeRawDataType } from "../type";

export interface TreeProps {
  treeData: TreeDataType;
  title?: string;
  /** 总数 */
  total?: number;
  /** 父节点添加子节点文案 */
  addChildText?: string;
  hiddenCount?: boolean;
  defaultExpandAll?: boolean;
  expandAll?: boolean;
  editable?: boolean;
  checkable?: boolean;
  //禁止选择根节点的复选框
  disabledCheckAll?: boolean;
  // 显示树结构最大层数
  maxShowDeepth?: number;
  // 允许增加子节点树结构最大层数
  maxCreateDeepth?: number;
  highlightSelected?: boolean;
  defaultSelected?: string | number; // 默认选中的节点
  selected?: string | number;
  defaultChecked?: Array<string | number>; // 默认选中复选框的树节点
  checked?: Array<string | number>; //受控，选中复选框的树节点
  className?: string;
  fullHeight?: boolean;
  onRootNodeSelect?: () => void; // 根节点点击事件
  nodeTitleChangeValidator?: (text: string) => string | undefined; // node 修改标题校验
  nodeTitleRender?: (node: TreeNodeType) => ReactNode;
  onSelect?: (key: string | number) => void;
  onCheck?: (keys: Array<string | number>) => void;
  onChange?: (treeData: TreeRawDataType) => void;
  onNodeTitleChange?: (
    key: string | number,
    title: string,
    treeData?: TreeDataType
  ) => void;
  onNodeRemove?: (key: string | number) => void;
  // TODO: 修改 keys 类型
  onNodeAdd?: (key: string | number, title: string) => void;
  onMockChildAdd?: (key: string | number) => void;
}

export interface TreeNodeProps {
  /** 父节点添加子节点文案 */
  addChildText?: string;
  currentKey: string | number;
  title: string;
  titleRender?: ReactNode;
  isLeaf: boolean;
  isLast: boolean;
  verticalLines: Array<boolean>;
  selected?: boolean;
  open?: boolean;
  editable?: boolean;
  isEditing?: boolean;
  checked?: boolean;
  checkable?: boolean;
  children?: TreeDataType;
  defaultExpandAll?: boolean;
  highlightSelected?: boolean;
  disableRemove?: boolean;
  disableAddChild?: boolean;
  disableEdit?: boolean; // 禁止编辑
  disableCheck?: boolean;
  count?: number;
  nodeTitleChangeValidator?: (title: string) => string | undefined;
  onClick?: () => void;
  onExpand?: (expand: boolean) => void;
  onTitleChange?: (title: string) => void;
  onNodeRemove?: () => void;
  onMockChildAdd?: () => void;
  onCancelEdit?: () => void;
  onCheck?: (checked: boolean) => void;
  onEdit?: () => void;
}

export type TreeNodeAddButtonType = {
  verticalLines: Array<boolean>;
  enableNewBranch?: boolean;
  onAdd: (type: "node" | "branch") => void;
};

export interface TreeRef {
  setOnEditingKey: (v: string | null) => void;
}
